home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gxmatrix.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.4 KB  |  88 lines

  1. /* Copyright (C) 1989, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gxmatrix.h,v 1.4 2000/09/19 19:00:39 lpd Exp $ */
  20. /* Internal matrix routines for Ghostscript library */
  21.  
  22. #ifndef gxmatrix_INCLUDED
  23. #  define gxmatrix_INCLUDED
  24.  
  25. #include "gsmatrix.h"
  26.  
  27. /*
  28.  * Define a matrix with a cached fixed-point copy of the translation.
  29.  * This is only used by a few routines in gscoord.c; they are responsible
  30.  * for ensuring the validity of the cache.  Note that the floating point
  31.  * tx/ty values may be too large to fit in a fixed values; txy_fixed_valid
  32.  * is false if this is the case, and true otherwise.
  33.  */
  34. typedef struct gs_matrix_fixed_s {
  35.     _matrix_body;
  36.     fixed tx_fixed, ty_fixed;
  37.     bool txy_fixed_valid;
  38. } gs_matrix_fixed;
  39.  
  40. /* Make a gs_matrix_fixed from a gs_matrix. */
  41. int gs_matrix_fixed_from_matrix(P2(gs_matrix_fixed *, const gs_matrix *));
  42.  
  43. /* Coordinate transformations to fixed point. */
  44. int gs_point_transform2fixed(P4(const gs_matrix_fixed *, floatp, floatp,
  45.                 gs_fixed_point *));
  46. int gs_distance_transform2fixed(P4(const gs_matrix_fixed *, floatp, floatp,
  47.                    gs_fixed_point *));
  48.  
  49. /*
  50.  * Define the fixed-point coefficient structure for avoiding
  51.  * floating point in coordinate transformations.
  52.  * Currently this is used only by the Type 1 font interpreter.
  53.  * The setup is in gscoord.c.
  54.  */
  55. typedef struct {
  56.     long xx, xy, yx, yy;
  57.     int skewed;
  58.     int shift;            /* see m_fixed */
  59.     int max_bits;        /* max bits of coefficient */
  60.     fixed round;        /* ditto */
  61. } fixed_coeff;
  62.  
  63. /*
  64.  * Multiply a fixed point value by a coefficient.  The coefficient has two
  65.  * parts: a value (long) and a shift factor (int), The result is (fixed *
  66.  * coef_value + round_value) >> (shift + _fixed_shift)) where the shift
  67.  * factor and the round value are picked from the fixed_coeff structure, and
  68.  * the coefficient value (from one of the coeff1 members) is passed
  69.  * explicitly.  The last parameter specifies the number of bits available to
  70.  * prevent overflow for integer arithmetic.  (This is a very custom
  71.  * routine.)  The intermediate value may exceed the size of a long integer.
  72.  */
  73. fixed fixed_coeff_mult(P4(fixed, long, const fixed_coeff *, int));
  74.  
  75. /*
  76.  * Multiply a fixed whose integer part usually does not exceed max_bits
  77.  * in magnitude by a coefficient from a fixed_coeff.
  78.  * We can use a faster algorithm if the fixed is an integer within
  79.  * a range that doesn't cause the multiplication to overflow an int.
  80.  */
  81. #define m_fixed(v, c, fc, maxb)\
  82.   (((v) + (fixed_1 << (maxb - 1))) &\
  83.     ((-fixed_1 << maxb) | _fixed_fraction_v) ?    /* out of range, or has fraction */\
  84.     fixed_coeff_mult((v), (fc).c, &(fc), maxb) : \
  85.    arith_rshift(fixed2int_var(v) * (fc).c + (fc).round, (fc).shift))
  86.  
  87. #endif /* gxmatrix_INCLUDED */
  88.